

function usernameInputChange(username,isRight,message) {
      let reg = /^[^_]\S{0,14}[^_]$/;
      console.log(reg.test(username));
      if (username.length === 0) {
        isRight = 0;
        message = "用户名不可为空!";
      } else if (username.length < 2) {
        isRight = 0;
        message = "用户名需大于2位!";
      } else if (username.length > 16) {
        isRight = 0;
        message = "用户名需小于16位!";
        username = username.slice(0, 16);
      } else if (!reg.test(username)) {
        isRight = 0;
        message = "用户名不能以下划线开头和结尾!";
      } else {
        isRight = 1;
        message = "";
      }
      return{
        isRight, message
      }
    };

function passwordInputChange(password,isRight,message) {
      let reg = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)(?![\W_]+$)\S{6,16}$/;
      // console.log(password);
      if (password.length === 0) {
        isRight = 0;
        message = "密码不可为空!";
      } else if (password.length < 6) {
        isRight = 0;
        message = "密码需大于6位!";
      } else if (password.length > 16) {
        isRight = 0;
        message = "用户名需小于16位!";
        password = password.slice(0, 16);
      } else if (!reg.test(password)) {
        isRight = 0;
        message =
          "密码需包含小写字母、大写字母、数字、特殊符号的两种及以上";
      } else {
        isRight = 1;
        message = "";
      }
      return{
          isRight,message,
      }
    };

export default{
    usernameInputChange,
    passwordInputChange,
}
